<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>命令模式</title>
  </head>
  <body></body>
  <script>
    class Receiver{
        execute(){
            console.log("接受者执行请求");
        }
    }

    class Command {
        constructor(receiver){
            this.receiver = receiver
        }

        execute(){
            console.log("命令对象 => 接受者如何处理")
            this.receiver.execute()
        }
    }

    class Invoker {
        constructor(command){
            this.command = command
        }
        execute(){
            console.log("请求执行命令");
            this.command.execute()
        }
    }

    // 命令对象接收接受者（处理工厂），生成做具体事情的订单
    const order = new Command(new Receiver())

    // 客户作为触发者下订单
    const client = new Invoker(order)

    // 客户执行
    client.execute()
  </script>
</html>
